package com.ij.media.intercept;

import com.ij.sso.utils.MsgCode;
import com.ij.sso.utils.MyExceptionUtil;
import com.ij.sso.utils.ReturnUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.MissingPathVariableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Component
public class MyExceptionHandler {
    @ExceptionHandler(MissingPathVariableException.class)
    public ReturnUtil MissingPathVariableExceptionHandler(Exception e){
        return ReturnUtil.fail("参数校验错误:"+e.getMessage(), MsgCode.CLIENT_ERROR);
    }
    @ExceptionHandler(RuntimeException.class)
    public ReturnUtil RuntimeExceptionHandler(Exception e){
        e.printStackTrace();
        return ReturnUtil.fail("token异常:"+e.getMessage(), MsgCode.CLIENT_ERROR);
    }
    @ExceptionHandler(MyExceptionUtil.class)
    public ReturnUtil MyException(Exception e){
        e.printStackTrace();
        return ReturnUtil.fail("程序发生异常:"+e.getMessage(), MsgCode.SERVER_ERROR);
    }
    @ExceptionHandler(Exception.class)
    public ReturnUtil exceptionHandler(Exception e){
        e.printStackTrace();
        return ReturnUtil.fail("程序发生异常:"+e.getMessage(), MsgCode.SERVER_ERROR);
    }
}
